package Rozetka.Pages;

import Rozetka.Pages.BasePage;
import Rozetka.ReportWriter.ReportWriter;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.NoSuchElementException;

public class RegistrationPage extends BasePage {

    private static By name = By.name("title");
    private static By email = By.name("email");
    private static By password = By.name("password");

    public RegistrationPage(WebDriver driver) {
        super(driver);
    }

    public void registrNewUser(String Name, String Email, String Password){
        ReportWriter.info("Register new User");
        try {
            driver.findElement(name).clear();
            driver.findElement(name).sendKeys(Name);

            driver.findElement(email).clear();
            driver.findElement(email).sendKeys(Email);

            driver.findElement(password).clear();
            driver.findElement(password).sendKeys(Password);

            driver.findElement(By.className("button-css-green")).click();
        } catch (NoSuchElementException e) {
            ReportWriter.error("Didn't find element.");
        }
    }

    public boolean isUserRegistred(String Name) {
        ReportWriter.info("Check is user registered");
        if (driver.findElement(By.className("field")).getText().contains(Name)) {
            ReportWriter.info("Positive registration is done");
            return true;
        } else {
            ReportWriter.error("Positive registration is failed");
            return false;
        }
    }

    public boolean registrationError() {
        ReportWriter.info("Check negative registration");
        if  (driver.findElement(By.name("app-message")).isEnabled() ) {
            ReportWriter.info("Check negative registration is done");
            return true;
        } else {
            ReportWriter.error("Check negative registration is failed");
            return false;
        }
    }

}
